<%@ page import="com.roadjava.tutor.bean.vo.UserVO" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>会员通用功能-欢迎页</title>
  <jsp:include page="../../common/common_resources.jsp"/>
  <style>
  </style>
</head>
<body>
<div class="layui-fluid mt-3">
  <div class="layui-row">
    <div class="layui-col-xs4 layui-col-xs-offset4">
      <form class="layui-form" action="" method="post" lay-filter="updateForm">
        <div class="layui-form-item">
          <label class="layui-form-label">用户标识</label>
          <div class="layui-input-block">
            <input type="text" name="id" lay-verify="required" class="layui-input" readonly>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="userName" lay-verify="required" class="layui-input" readonly>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">地址</label>
          <div class="layui-input-block">
            <input type="text" name="addr" lay-verify="required" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">电话</label>
          <div class="layui-input-block">
            <input type="text" name="phone" lay-verify="required|phone" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">邮箱</label>
          <div class="layui-input-block">
            <input type="text" name="email" lay-verify="required|email" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="updateBtn">修改</button>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<script>
  layui.use(['jquery', 'form'], function ($,form) {
    $.ajax({
      url: '<%=request.getContextPath() %>/memberCommon/selectOneById',
      data: {id: ${sessionScope.user.id}},
      success: function (result) {
        if (result.success) {
          var selected = result.data;
          form.val("updateForm", { // 为表单赋值
            "id": selected.id, // key为表单元素的name
            "userName": selected.userName,
            "addr": selected.addr,
            "phone": selected.phone,
            "email": selected.email
          });
        } else {
          layer.open({
            content: result.errMsg,
            icon: 5, // 快哭了
            anim: 6 // 0-6 不同的效果
          });
        }
      }
    });
    // 编辑书籍类型表单提交事件
    form.on('submit(updateBtn)', function (data) {
      $.ajax({
        url: '<%=request.getContextPath() %>/memberCommon/trueUpdate',
        method: 'post',
        data: data.field,
        success: function (result) {
          if (result.success) {
            layer.open({
              content: result.data,
              icon: 6, // 0-6,6:开心
              anim:0
            });
          } else {
            layer.open({
              content: result.errMsg,
              icon: 5, // 快哭了
              anim: 6 // 0-6 不同的效果
            });
          }
        }
      });
      return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
  });
</script>
</body>
</html>
